package com.int_tech.control.dao;

import com.int_tech.control.entity.SocketLog;
import com.int_tech.control.entity.SocketLogSend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * Created by liubch on 2017/11/24.
 */
public interface SocketLogDao extends JpaRepository<SocketLog,Integer> {
//    List<SocketLog> findByCreateTimeAfterAndCreateTimeBeforAndDataStringLike(Date createTime, Date endTime, String key);


//    @Query("select s from SocketLog s where s.createdTime >=?1 and s.createdTime <=?2 and s.dataString like ?3")
//    List<SocketLog> findLogs(@Param("createTime")Date createTime, @Param("endTime")Date endTime, @Param("key")String key);

    List<SocketLog> findByDataStringOrderByCreateTimeDesc(String key);

    @Query("select s from SocketLog s where s.dataString like CONCAT('%',:key,'%') ")
    List<SocketLog> findByDataStringLikeOrderByCreateTimeDesc(@Param("key") String key);

    List<SocketLog> findByDataStringLike(String key);

    List<SocketLog> findByStatus(int status);

    @Query("select s from SocketLog s where s.status=?1 group by s.carNumber order by s.createTime asc ")
    List<SocketLog> findLogGroupByCarNumber(int status);

    @Query("select s from SocketLog s where s.status=?2 and s.carNumber=?1 order by s.createTime asc ")
    List<SocketLog> findByCarNumberAndStatus(@Param("carNumber") String carNumber, @Param("status") int status);

    @Query("select s from SocketLog s where s.code=?1 and s.serviceType=?2 and s.status=?3 group by s.carNumber order by s.createTime asc ")
    List<SocketLog> findLogByCodeAndServiceTypeGroupByCarNumber(@Param("code")String code, @Param("serviceType")String serviceType, @Param("status")int status);

    @Query("select s from SocketLog s where s.code=?3 and s.serviceType=?4 and s.status=?2 and s.carNumber=?1 order by s.createTime asc ")
    List<SocketLog> findByCarNumberAndStatusAndCodeAndServiceType(@Param("carNumber")String carNumber, @Param("status")int status,@Param("code")String code,@Param("serviceType")String serviceType);

    @Query("select s from SocketLog s where s.dataString like CONCAT('%',?1,'%') and s.createTime >=?2 order by s.createTime desc ")
    List<SocketLog> findByDataStringLikeAndCreateTimeAfterOrderByCreateTimeDesc(String key, Date date);

}
